package com.interview.semaphore;

import java.security.KeyStore;
import java.util.Random;

public class UserThread extends Thread {
    private final static Random random = new Random(26535);
    private final BoundedResource resource;

    public UserThread( BoundedResource resource) {
        this.resource = resource;
    }

    public void run(){
        while (true){
            try {
                resource.doUse();
                Thread.sleep(random.nextInt(3000));
            } catch (InterruptedException e) {
            }
        }
    }

    public static void main(String[] args) {
        //设置3个资源
        BoundedResource boundedResource = new BoundedResource(3);

        //十个线程使用资源
        for (int i = 0; i < 10; i++) {
           new UserThread(boundedResource).start();
        }
    }
}
